<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Unite_model extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    public function getList() {
        return $this->db
                        ->select('UNITE_ID, UNITE_LIBELLE, UNITE_CODE')
                        ->from('UNITE_MESURE')
                        ->get()
                        ->result();
    }

    public function get($UNITE_ID) {
        $result = $this->db
                ->select('UNITE_ID, UNITE_LIBELLE, UNITE_CODE')
                ->from('UNITE_MESURE')
                ->where('UNITE_ID', $UNITE_ID)
                ->get()
                ->result();

        if (count($result) == 1) {
            $result = $result[0];
        }

        return $result;
    }

    /***************************************************************************
     * Méthodes d'enregistrement
     **************************************************************************/
    public function create($UNITE_LIBELLE, $UNITE_CODE) {
        $this->db->set('UNITE_LIBELLE', $UNITE_LIBELLE)
                ->set('UNITE_CODE', $UNITE_CODE)
                ->insert('unite');
    }

    public function update($UNITE_ID, $UNITE_LIBELLE, $UNITE_CODE) {
        $data = array(
            'UNITE_LIBELLE' => $UNITE_LIBELLE,
            'UNITE_CODE' => $UNITE_CODE
        );
        $this->db->where('UNITE_ID', $UNITE_ID)
                ->update('unite', $data);
    }

    public function Delete($UNITE_ID) {
        $this->db->where('UNITE_ID', $UNITE_ID)
                ->delete('unite');
    }

}

?>